const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class EditWallHandler extends BaseHandler {

    get pattern() {
        return '/walls/:wall_id/edit';
    }

    doGET(request, response) {
        var me = this;
        if(!request.session.user.authenticated) {
            response.redirect('/login?ref=expired');
        } else {
            var userId = request.session.user.id;
            this.Controller.getWallById(request.params.wall_id, (data) => {
                var tag_source = encodeURI(JSON.stringify(data.tag_source));
                me.Controller.getPlanInfo(userId, (result) => {
                    response.render('console/edit', {
                        user: request.session.user,
                        data: data,
                        tag_source:tag_source || [],
                        settings: data.settings,
                        tag_authority: data.tag_authority || '',
                        wall_id: request.params.id,
                        plan: result.data
                    });
                });
            });
        }
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = EditWallHandler;